<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <h2 ref="myh2">这是 h2 标题</h2>
    <button @click="show">ref获取DOM</button>
    <hr>
    <button @click="show2">调用 子组件</button>
    <login ref="mylogin"></login>
  </div>
  <script src="libs/vue.js"></script>
  <script>
    var login = {
      template: '<div><h1>这是一个 登录组件</h1></div>',
      data() {
        return {
          msg: 'hello world'
        }
      },
      methods: {
        print() {
          console.log('这里是子组件')
        }
      },
      watch: {
        msg() {
          console.log(this.msg)
        }
      },
    }
    var vm = new Vue({
      el: '#app',
      data: {
        content: '这是 父组件 中的数据'
      },
      methods: {
        show() {
          console.log(this.$refs.myh2.innerText)
        },
        show2() {
          this.$refs.mylogin.print()
          console.log(this.$refs.mylogin.msg)
          this.$refs.mylogin.msg = '在 父组件 中修改 子组件 的内容'
        }
      },
      components: {
        login
      }
    })
  </script>
</body>
</html>